package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PipeConfiguration;
import com.ruoyi.system.service.IPipeConfigurationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 管道配置Controller
 * 
 * @author ruoyi
 * @date 2024-01-22
 */
@RestController
@RequestMapping("/system/configuration")
public class PipeConfigurationController extends BaseController
{
    @Autowired
    private IPipeConfigurationService pipeConfigurationService;

    /**
     * 查询管道配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:configuration:list')")
    @GetMapping("/list")
    public TableDataInfo list(PipeConfiguration pipeConfiguration)
    {
        startPage();
        List<PipeConfiguration> list = pipeConfigurationService.selectPipeConfigurationList(pipeConfiguration);
        return getDataTable(list);
    }

    /**
     * 导出管道配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:configuration:export')")
    @Log(title = "管道配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PipeConfiguration pipeConfiguration)
    {
        List<PipeConfiguration> list = pipeConfigurationService.selectPipeConfigurationList(pipeConfiguration);
        ExcelUtil<PipeConfiguration> util = new ExcelUtil<PipeConfiguration>(PipeConfiguration.class);
        util.exportExcel(response, list, "管道配置数据");
    }

    /**
     * 获取管道配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:configuration:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(pipeConfigurationService.selectPipeConfigurationById(id));
    }

    /**
     * 新增管道配置
     */
    @PreAuthorize("@ss.hasPermi('system:configuration:add')")
    @Log(title = "管道配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PipeConfiguration pipeConfiguration)
    {
        return toAjax(pipeConfigurationService.insertPipeConfiguration(pipeConfiguration));
    }

    /**
     * 修改管道配置
     */
    @PreAuthorize("@ss.hasPermi('system:configuration:edit')")
    @Log(title = "管道配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PipeConfiguration pipeConfiguration)
    {
        return toAjax(pipeConfigurationService.updatePipeConfiguration(pipeConfiguration));
    }

    /**
     * 删除管道配置
     */
    @PreAuthorize("@ss.hasPermi('system:configuration:remove')")
    @Log(title = "管道配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(pipeConfigurationService.deletePipeConfigurationByIds(ids));
    }
}
